<template>
  <div>
    <div class="marquee">
      <!-- <div class="marquee_title">
        <span>最新战报</span>
      </div> -->
      <div class="marquee_box"
           :style="{'height': listRow * 72 + 'px'}">
        <!-- marquee_list_single: listRow === 1 -->
        <ul class="marquee_list"
            :class="{marquee_top: animate}">
          <!-- :class="{active: (index === 1 && !animate) || (index === 2 && animate)}" -->
          <li v-for="(item, index) in marqueeList"
              :style="{'width': (100 / listCol) + '%'}"
              :key="index">
            <span>恭喜</span>
            <span>{{item.mobile | phoneReplace}}</span>
            <span>已获得</span>
            <span v-if="packet" class="redpacket"></span>
            <span v-else>￥{{item.amount}}</span>
            <span>{{item.amount}}元现金红包</span>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { phoneReplace } from '@/tool/tool'
export default {
  name: 'slideLst',
  components: {
  },
  props: {
    list: {
      type: Array,
      default: () => []
    },
    listRow: {
      type: Number,
      default: 1
    },
    listCol: {
      type: Number,
      default: 1
    },
    packet: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      animate: false,
      marqueeList: [],
      timmerRoll: null,
      timmerCol: null
    }
  },
  methods: {
    showMarquee () {
      // console.log(this.timmerRoll)
      clearTimeout(this.timmerRoll)
      this.timmerRoll = setTimeout(() => {
        this.animate = true
        // 总数小于每行个数时停止轮播
        if (this.marqueeList.length < this.listCol) {
          return
        }
        clearTimeout(this.timmerCol)
        this.timmerCol = setTimeout(() => {
          // this.marqueeList = this.marqueeList.concat(this.marqueeList.slice(0, this.listCol)).slice(this.listCol)
          this.marqueeList.push.apply(this.marqueeList, this.marqueeList.slice(0, this.listCol))
          this.marqueeList.splice(0, this.listCol)
          this.animate = false
        }, 1500)
        this.showMarquee()
      }, 1500)
    }
  },
  mounted () {
  },
  filters: {
    phoneReplace
  },
  created () {
    this.marqueeList = this.list
    if (this.marqueeList.length) {
      this.showMarquee()
    }
  },
  watch: {
    list: {
      deep: true,
      handler (newVal) {
        if (newVal.length) {
          this.marqueeList = newVal
          this.showMarquee()
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
div,
ul,
li,
span,
img {
  margin: 0;
  padding: 0;
  display: flex;
  box-sizing: border-box;
}
.marquee {
  width: 100%;
  align-items: center;
  color: #3a3a3a;
  background-color: #ffffff;
  display: flex;
  box-sizing: border-box;
  .marquee_title {
    padding: 0 20px;
    height: 72px;
    font-size: 16px;
    border-right: 1px solid #d8d8d8;
    align-items: center;
  }
  .marquee_box {
    display: block;
    position: relative;
    width: 100%;
    overflow: hidden;
    .marquee_list {
      width: 100%;
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      li {
        height: 72px;
        line-height: 72px;
        font-size: 16px;
        float: left;
        padding-left: 20px;
        border-bottom: 1px solid #f0f0f0;
        span {
          display: inline-block;
          padding: 0 2px;
          color: #333333;
          text-align: center;
          &:nth-of-type(1) {
            width: 10%;
          }
          &:nth-of-type(2) {
            width: 34.34%;
            font-size: 20px;
            font-weight: 500;
            text-align: left;
          }
          &:nth-of-type(3) {
            width: 13.2%;
            color: #666666;
          }
          &:nth-of-type(4) {
            height: 27px;
            line-height: 27px;
            text-align: center;
            display: inline-block;
            font-size: 9px;
            color: #ffffff;
            background-color: #eb0101;
            border-radius: 6px;
            margin-top: 21.5px;
          }
          &:nth-of-type(5) {
            width: 34.63%;
            font-size: 20px;
            font-weight: 500;
            color: #fb0000;
          }
          &.redpacket{
            background: url(../pages/activity/december/img/redpacket.png);
            width: 22px;
            background-size: 100% 100%;
          }
        }
      }
    }
    // 单行渐变动画
    // .marquee_list_single {
    //   top: -24px;
    //   li {
    //     height: 24px;
    //     font-size: 14px;
    //     opacity: 0.5;
    //     padding-left: 20%;
    //     padding-right: 20%;
    //     span {
    //       &:nth-of-type(1) {
    //         color: #ff0000;
    //       }
    //       &:nth-of-type(2) {
    //         font-size: 21px;
    //         color: #ff0000;
    //       }
    //       &:nth-of-type(3) {
    //         color: #ff0000;
    //       }
    //       &:nth-of-type(4) {
    //         display: none;
    //       }
    //       &:nth-of-type(5) {
    //         font-size: 21px;
    //         color: #ff0000;
    //       }
    //     }
    //   }
    //   .active {
    //     height: 24px;
    //     opacity: 1;
    //     padding-left: 7.5%;
    //     padding-right: 7.5%;
    //     span {
    //       transform: scale(1.238);
    //       &:nth-of-type(1) {
    //         width: 16.4%;
    //         transform: scale(1.2857);
    //         color: #ff0000;
    //       }
    //       &:nth-of-type(2) {
    //         width: 31.93%;
    //       }
    //       &:nth-of-type(3) {
    //         width: 11.879%;
    //       }
    //       &:nth-of-type(4) {
    //         display: none;
    //       }
    //       &:nth-of-type(5) {
    //         width: 39.74%;
    //         transform: scale(1.2857);
    //       }
    //     }
    //   }
    // }
    .marquee_top {
      transition: all 1.5s linear;
      margin-top: -72px;
      // li {
      //   transition: all 1.5s linear;
      //   span {
      //     transition: all 1.5s linear;
      //   }
      // }
    }
    // .marquee_list_single.marquee_top {
    //   transition: all 1.5s linear;
    //   margin-top: -24px;
    // }
  }
}
</style>
